<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>图片预加载之无序加载--qq表情</title>

	<style media="screen">
		body,p,ul,li{
			padding: 0;
			margin: 0;
		}
		body{
			background-color: #eee;
		}
		.box{
			margin: 150px 0 0 200px;
		}
		a{
			text-decoration: none;
		}
		li{
			list-style-type: none;
		}
		#face-btn{
			display: block;
			background: url(img/icon.gif) no-repeat 0 0;
			text-indent: 20px;
			color: #333;
		}
		.panel{
			display: none;
			width: 390px;
			padding: 2px;
			border: 1px solid #ccc;
			background-color: #fff;
		}
		.list li{
			display: inline-block;
			width: 24px;
			height: 24px;
			border: 1px solid #fff;
			margin-bottom: 5px;
			cursor: pointer;
		}
		.list li:hover{
			border-color: #06c;
		}
	</style>
</head>
<body>
	<div class="box">
		<a href="javascript:;" id="face-btn">表情</a>
		<div class="panel">
			<p class="loading">表情加载中，请稍后...</p>
			<ul class="list"></ul>
		</div>
	</div>
	<script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
	<script src="preload.js"></script>
	<script type="text/javascript">
		var $btn = $('#face-btn'),
				$panel = $('.panel');
		var imgs = [];

		for(var i=0; i< 75; i++){
			imgs[i] = 'face/QQ/' + (i + 1) + '.gif';
		}

		var len = imgs.length;
		$btn.on('click', function(e){
			e.stopPropagation();
			$panel.show();
			$.preload(imgs, {
				all: function(){
					var html = '';
					html += '<ul class="list">';
					for(var i=0; i<len; i++){
						html += '<li><img src="' + imgs[i] + '" alt=""></li>';
					}
					html += '</ul>';

					setTimeout(function(){
						$panel.html(html);
					}, 1000)
				}
			});
		});

		$(document).on('click', function(){
			$panel.hide();
		})
	</script>
</body>
</html>
